package cn.itcast.staticandfinal;

/**
 * @title: StaticField
 * @Author Zhou
 * @Date: 2022/1/21 11:26
 * @Version 1.0
 */
public class StaticField {
    public static void main(String[] args) {
        StaticF harry = new StaticF();
        harry.setId();
        System.out.println("harry = " + harry);
        StaticF staticF = new StaticF();
        staticF.setId();
        System.out.println("staticF = " + staticF);
        System.out.println(staticF.getNextId());
    }
}

class StaticF {
    private static int nextId = 1;
    private int id;

    public void setId() {
        id = nextId;
        nextId++;
    }

    @Override
    public String toString() {
        return "StaticF{" +
                "id=" + id +
                '}';
    }

    public int getNextId() {
        return nextId;
    }

    public void setNextId(int nextId) {
        StaticF.nextId = nextId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}